package com.qf.flash.ui.home.adapter;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.qf.flash.R;
import com.qf.flash.http.response.BusinessInfoBean;
import com.qf.flash.utils.ImageLoader;
import com.qf.flash.widget.RatingBarView;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

/**
 * 创建日期：2020/3/8 on 21:22
 * 描述:
 * 作者:戴旭东
 */
public class ChoseBusinessItem extends BaseRViewItem<BusinessInfoBean> {

    private Context context;

    public ChoseBusinessItem(Context context) {
        this.context = context;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_chosen_business;
    }

    @Override
    public void convert(RViewHolder holder, BusinessInfoBean entity, int position, int itemSize) {
        ImageView ivImg = holder.getView(R.id.iv_img);
        RatingBarView rbvStar = holder.getView(R.id.rbv_star);
        rbvStar.setStar(Math.round(entity.getResponseScole()), false);
        CheckBox cbRight = holder.getView(R.id.cb_right);
        if (position == holder.getAdapter().getSingleChosenPosition()) {
            cbRight.setChecked(true);
        } else {
            cbRight.setChecked(false);
        }
        holder.setOnClickListener(cbRight);
        holder.setOnClickListener(R.id.cl_container);

        ImageLoader.load(context, entity.getPhoto(), ivImg);

        holder.setText(R.id.tv_name, entity.getShopName())
                .setText(R.id.tv_type_address, entity.getLocation())
                .setText(R.id.tv_score, entity.getResponseScole() + "分")
                .setText(R.id.tv_distance, entity.getRangeNumStr());

    }
}
